package com.gis507.mapreduce.track;

import com.gis507.mapreduce.AISBean.AnalysisIndex;
import com.gis507.mapreduce.Utils.UtilsClass;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class AISInterpolationMapper extends Mapper<LongWritable,Text, Text, AnalysisIndex> {

    private Text outK = new Text();
    private AnalysisIndex outV = new AnalysisIndex();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        String line = value.toString();

        String[] comment = line.split(",");

        //private String mmsi;
        //    private Long unixTime;
        //    private Double speed;
        //    private Double heading;     // 对地航向
        //    private Double course;      // 真航向
        //    private Double lon_d;
        //    private Double lat_d;
        //    private Double distance = -1.0;    // 距离
        //    private Long diffTime = -1L;
        //    private Double diffSpeed = -1.0;
        //    private Double diffHeading = -1.0;
        //    private Double diffCourse = -1.0;
        String mmsi = comment[0];
        Long unixTime = new Long(comment[1]);
        double speed = new Double(comment[2]);

        double heading = new Double(comment[3]);
        double course = new Double(comment[4]);
        double lon_d = new Double(comment[5]);
        double lat_d = new Double(comment[6]);
        Double distance = new Double(comment[7]);
        Long diffTime = new Long(comment[8]);
        Double diffSpeed = new Double(comment[9]);
        Double diffHeading = new Double(comment[10]);
        Double diffCourse = new Double(comment[11]);

        //fengzhuang
        outK.set(mmsi);

        outV.setMmsi(mmsi);
        outV.setHeading(heading);
        outV.setCourse(course);
        outV.setSpeed(speed);
        outV.setUnixTime(unixTime);
        outV.setLon_d(lon_d);
        outV.setLat_d(lat_d);
        outV.setDistance(distance);
        outV.setDiffTime(diffTime);
        outV.setDiffSpeed(diffSpeed);
        outV.setDiffHeading(diffHeading);
        outV.setDiffCourse(diffCourse);


        //write for Mapper
        context.write(outK, outV);

    }


}
